package com.factory.test.m5622;

import android.os.Bundle;
import android.widget.CompoundButton;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.factory.test.R;
import com.factory.test.base.BaseTestActivity;
import com.factory.test.databinding.ActivityM5622LedBinding;
import com.yecontech.sdk.base.gpio.GpioCustom;

/**
 * LED灯带测试
 */
public class LedActivity extends BaseTestActivity {

    private ActivityM5622LedBinding binding;
    private GpioCustom led1Gpio;
    private GpioCustom led2Gpio;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_m5622_led);


        led1Gpio = sdkService.getGpioCustomManager();
        led1Gpio.init("0", 0, null);
        binding.led1.setChecked(led1Gpio.getAction() == 1);
        binding.led1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                led1Gpio.setAction(isChecked ? 1 : 0);
            }
        });

        led2Gpio = sdkService.getGpioCustomManager();
        led2Gpio.init("5", 0, null);
        binding.led2.setChecked(led2Gpio.getAction() == 1);
        binding.led2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                led2Gpio.setAction(isChecked ? 1 : 0);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        led1Gpio.release();
        led2Gpio.release();
    }
}
